<?php

namespace app\models;

use Yii;

/**
 * This is the model class for table "customer_address".
 *
 * @property int $id
 * @property int $customer_id 用户id
 * @property string $name 姓名
 * @property string $phone 电话
 * @property int $area_id 区域id
 * @property string $address 详细地址
 * @property int $default 是否默认地址
 * @property int $status 状态
 * @property int $created_at 创建时间
 */
class CustomerAddress extends Base
{
    /**
     * {@inheritdoc}
     */
    public static function tableName()
    {
        return 'customer_address';
    }

    /**
     * {@inheritdoc}
     */
    public function rules()
    {
        return [
            [['customer_id', 'gender', 'area_id', 'default', 'status', 'created_at'], 'integer'],
            [['name', 'phone', 'address'], 'string', 'max' => 255],
        ];
    }

    /**
     * {@inheritdoc}
     */
    public function attributeLabels()
    {
        return [
            'id' => 'ID',
            'customer_id' => 'Customer ID',
            'name' => 'Name',
            'phone' => 'Phone',
            'area_id' => 'Area ID',
            'address' => 'Address',
            'default' => 'Default',
            'status' => 'Status',
            'created_at' => 'Created At',
        ];
    }

    public function getCustomer(){
        return $this->hasOne(Customer::class, ['id' => 'customer_id']);
    }

    public function getArea(){
        return $this->hasOne(Area::class, ['id' => 'area_id']);
    }
}
